package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.TransportLoginWx;
import com.hunttown.mes.rpc.exception.ConvertException;
import com.hunttown.mes.rpc.domain.TransportLoginWxDTO;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2019-05-18 20:14:18
 */
public class TransportLoginWxConverts {

    private static Logger LOG = LoggerFactory.getLogger(TransportLoginWxConverts.class);

    public static List<TransportLoginWxDTO> convert(List<TransportLoginWx> transportLoginWxList) {
        if (CollectionUtils.isEmpty(transportLoginWxList)) {
            return Collections.EMPTY_LIST;
        }

        List<TransportLoginWxDTO> transportLoginWxListResult = Lists.newArrayList();
        for (TransportLoginWx transportLoginWx : transportLoginWxList) {
            transportLoginWxListResult.add(convert(transportLoginWx));
        }
        return transportLoginWxListResult;
    }

    public static TransportLoginWxDTO convert(TransportLoginWx transportLoginWx) {
        try {
            return BeanUtils.copy(transportLoginWx, TransportLoginWxDTO.class);
        } catch (Exception e) {
            LOG.error("TransportLoginWx到TransportLoginWxDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "TransportLoginWx到TransportLoginWxDTO转换失败", e);
        }
    }

    public static TransportLoginWx convert(TransportLoginWxDTO transportLoginWxDTO) {
        try {
            return BeanUtils.copy(transportLoginWxDTO, TransportLoginWx.class);
        } catch (Exception e) {
            LOG.error("TransportLoginWxDTO到TransportLoginWx转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "TransportLoginWxDTO到TransportLoginWx转换失败", e);
        }
    }
}